package com.gpy.hospital.cms.controller;

import com.github.pagehelper.PageInfo;
import com.gpy.hospital.cms.pojo.BingFang;
import com.gpy.hospital.cms.service.IXuanZuoService;
import com.gpy.hospital.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author
 * @Date 2020/3/27 10:14
 * @Desc
 **/
@Controller
public class BingFangController {
    @Autowired
    private IXuanZuoService xuanZuoService;

    @GetMapping("/page/bing/fang")
    public String blogPage() {
        return "/cms/bingFangList";
    }

    /**
     * 跳转到博客界面
     */
    @RequestMapping("/bing/fang/data")
    @ResponseBody
    public ServerResponse blogPage(@RequestParam(value = "num", required = false) String num,
                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<BingFang> blogs = xuanZuoService.getAllBingFang(pageNum, pageSize, num);
        return ServerResponse.createBySuccess("查询成功！", blogs.getList(), blogs.getTotal());
    }

    @GetMapping("/cms/bing/fang/canel")
    @ResponseBody
    public void bingFangEdit(@RequestParam("id") Integer id ) {
        xuanZuoService.updateByNull(id);

    }


    @GetMapping(" /cms/bing/fang/delete")
    @ResponseBody
    public ServerResponse bingFangDelete(@RequestParam("id") Integer id ) {
        return xuanZuoService.delete(id);

    }



    @GetMapping("/cms/bing/fang/add/lou/ceng/page")
    public String bingFangAddLouCeng() {
       return "/cms/bingFangAddLouCengPage";

    }

    @PostMapping("/cms/bing/fang/add/")
    @ResponseBody
    public ServerResponse bingFangAdd(BingFang bingFang) {
        return xuanZuoService.add(bingFang);

    }

    @GetMapping("/cms/bing/fang/add/fang/jian/page")
    public String bingFangAddFangJian(Model model) {
        List<BingFang> bingFangLists = xuanZuoService.getAllByLevel();
        model.addAttribute("bingFangLists", bingFangLists);
        return "/cms/bingFangAddFangJianPage";
    }

    @PostMapping("/cms/bing/fang/add/ss")
    @ResponseBody
    public ServerResponse bingFangAddss(BingFang bingFang) {
        return xuanZuoService.addss(bingFang);

    }



}
